// utils.js
const axios = require("axios");
const { wechatWebhookUrl } = require("./config");

const axiosInstance = axios.create({
  proxy: false, // 明确指定不使用代理
});

async function checkWebsite(url) {
  try {
    const response = await axiosInstance.get(url);
    console.log(`Checking ${url}:`, response.status);
    return response.status === 200;
  } catch (error) {
    return false;
  }
}

async function sendWechatNotification(message) {
  try {
    await axiosInstance.post(wechatWebhookUrl, {
      msgtype: "text",
      text: {
        content: message,
      },
    });
  } catch (error) {
    console.error("Failed to send WeChat notification:", error);
  }
}

module.exports = { checkWebsite, sendWechatNotification };
